//
//  MHBaseSearhViewController.m
//  MiaoCircle
//
//  Created by 许正荣 on 2018/10/12.
//  Copyright © 2018年 acgera. All rights reserved.
//

#import "MHBaseSearhViewController.h"

@interface MHBaseSearhViewController ()<JKRSearchControllerhResultsUpdating, JKRSearchControllerDelegate>

@end

@implementation MHBaseSearhViewController

-(JKRSearchController *) configSearchViewControllerWithResultViewController:(MHViewController<JKRSearchBarDelegate> *) resultViewController
{
    if (!_searchController) {
        _searchController = [[JKRSearchController alloc] initWithSearchResultsController:resultViewController];
        _searchController.searchBar.placeholder = @"搜索";
        _searchController.hidesNavigationBarDuringPresentation = YES;
        _searchController.searchResultsUpdater = self;
        _searchController.searchBar.delegate = resultViewController;
        _searchController.delegate = self;
        [self.view addSubview:self.searchController.searchBar];
        [self.searchController.searchBar mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(@15);
            make.top.equalTo(@(20 + MH_APPLICATION_TOP_BAR_HEIGHT));
            make.width.equalTo(self.view).offset(-30);
            make.height.equalTo(@35);
        }];
    }
    return _searchController;
}

#pragma mark -  JKRSearchControllerhResultsUpdating
- (void)updateSearchResultsForSearchController:(JKRSearchController *)searchController {
}

#pragma mark - JKRSearchControllerDelegate
- (void)willPresentSearchController:(JKRSearchController *)searchController {
    
    [self.searchController.searchBar mas_updateConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(@15);
        make.top.equalTo(@(zh_topSafeAreaHeight() + (MH_IS_IPHONE_X ? 10 : 20)  ));
        make.width.equalTo(self.view).offset(-30);
        make.height.equalTo(@35);
    }];
    
}

- (void)didPresentSearchController:(JKRSearchController *)searchController {
}

- (void)willDismissSearchController:(JKRSearchController *)searchController {
    
    [self.searchController.searchBar mas_updateConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(@15);
        make.top.equalTo(@(20 + MH_APPLICATION_TOP_BAR_HEIGHT));
        make.width.equalTo(self.view).offset(-30);
        make.height.equalTo(@35);
    }];
}

- (void)didDismissSearchController:(JKRSearchController *)searchController {
    
}


@end
